<include file="Common/header" xmlns="http://www.w3.org/1999/html"/>
<div class="container">
    <div class="row">

            <include file="Tools/tools-sidber" />

        <div class="col-md-10">
            <div class="page-header"><h3>{$page_title}</h3></div>
            <a  class="btn btn-default" href="{:U('Navs/index')}">菜单</a>
            <a  class="btn btn-default" href="{:U('Navs/add')}">菜单添加 </a>
            <br><br>
            <div>
                <table class="table table-bordered ">
                    <thead>
                    <tr class="active">
                        <td>id</td>
                        <td>排序</td>
                        <td> 菜单名称</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="navs" item="n">
                        <tr>
                            <td>{$n['id']}</td>
                            <td><input type="text" value="{$n['sort']}" onchange="changeSort(this,{$n['id']})"></td>
                            <td>{$n['name']}</td>
                            <td>
                                <if condition="$n['status']">
                                    <span class="label label-success">开启</span>
                                    <else/>
                                    <span class="label label-danger">关闭</span>
                                </if>
                            </td>
                            <td>
                                <a class="btn btn-primary" href="{:U('Navs/edit',array('id'=>$n['id']))}" >编辑</a>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:delNavs({$n['id']})">删除</a>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>
        </div>

</div>
    <script>
        function delNavs(id)
        {
            layer.confirm(' 确认删除',{
             btn:['是','不']
        } ,function () {
                $.ajax({
                  'url':"{:U('Navs/delete')}",
                    'type':'POST',
                    'dataType':'json',
                    'data':{'id':id},
                    success:function(phpReturnData){
                      if(phpReturnData.status==1){
                          layer.msg(phpReturnData.message,{'icon':6},function () {
                              window.location=location;
                          } )
                      }else{
                          layer.msg(phpReturnData.message,{'icon':5});
                      }
                }
                })
            })
        }
        function changeSort(obj,id) {
            //alert(id);
            var csort = $(obj).val();
            $.ajax({
                'url': "{:U('navs/changeSort')}",
                'type': 'post',
                'dataType': 'json',
                'data': {'id':id, 'sort': csort},
                success:function(phpReturnData)
                {
                    if (phpReturnData.status)
                    {
                        layer.msg(phpReturnData.message, {'icon': 6}, function () {
                            window.location = location;
                        })
                    }
                }
            })
        }
    </script>
<include file="Common/footer" />